/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jibble.pircbot.*;

/**
 *
 * @author Aksel Kvitberg
 */
public class AnnoyingBot extends PircBot {

//	public ArrayList<String> annoyUser
	public String annoyUser;

	public AnnoyingBot() {
		this.setName("AnnoyBot2");
		this.setLogin("annoyingBot2");
		try {
			this.connect("irc.lessthan3.net");
			this.joinChannel("#zubac2");
		} catch (IOException ex) {
			Logger.getLogger(AnnoyingBot.class.getName()).log(Level.SEVERE, null, ex);
		} catch (IrcException ex) {
			Logger.getLogger(AnnoyingBot.class.getName()).log(Level.SEVERE, null, ex);
		}
	}

	public void onMessage(String channel, String sender, String login, String hostname, String message) {
		if (message.contains(this.getNick() + " annoy ")) {
			String[] bulks = message.split(" ");
			try {
				annoyUser = bulks[2];
			} catch (Exception e) {
				System.err.println("Something wrong happened.");
			}
		}
		if (annoyUser != null & sender.equals(annoyUser)) {
			sendMessage(channel, message);
		}
		if (message.contains("join #") && message.length() > (this.getNick().length() + 8)) {
			this.joinChannel(message.substring(getNick().length() + 5));
		}
		if (message.contains(this.getNick() + " stop")){
			annoyUser = null;
		}
	}

	public static void main(String args[]) {
		new AnnoyingBot();
	}
}
